package util;

import java.io.Serializable;
import java.util.HashMap;

public class Translator implements Serializable {

	private static final long serialVersionUID = 1L;
	
	public static final int ES = 0;
	public static final int EN = 1;
	
	private HashMap<String, HashMap<String, String>> langMap;
	private HashMap<String, String> en;
	private String lang;
	
	public Translator(int l) {
		this();
		setLanguage(l);
	}
	
	public Translator() {
		lang = "en";
		langMap = new HashMap<String, HashMap<String, String>>();
		
		//Matare a  kien rompa el orden alfabeico.
		
		en = new HashMap<String, String>();
		en.put("Acerca de", "About us");
		en.put("Alquiler", "Rent");
		en.put("Anuncia", "Advertise");
		en.put("Ant", "Prev");
		en.put("buscar", "search");
		en.put("Buscar", "Search");
		en.put("Casa terrera", "House");
		en.put("Casas terreras", "Houses");
		en.put("Caracter&iacute;sticas", "Characteristics");
		en.put("C&oacute;digo de validaci&oacute;n", "Validation code");
		en.put("Confirmar", "Confirm");
		en.put("Contacta", "Contact");
		en.put("Contrase&ntilde;a", "Password");
		en.put("Correo", "Mail");
		en.put("Cualquiera", "Any");
		en.put("Dimensiones", "Dimensions");
		en.put("Direcci&oacute;n", "Address");
		en.put("direcci&oacute;n", "address");
		en.put("Edad", "Age");
		en.put("Entrar", "Login");
		en.put("Entre", "Between");
		en.put("Enviar", "Send");
		en.put("Error en la conexion con la base de datos", "Error establishing connection to the database");
		en.put("Espa&ntilde;ol", "Spanish");
		en.put("Halladas", "Found");
		en.put("Identificaci&oacute;n inv&aacute;lida", "Invalid Identification");
		en.put("Identificado como", "Logged as");
		en.put("Ingl&eacute;s", "English");
		en.put("inmuebles", "properties");
		en.put("Inmuebles", "Properties");
		en.put("Invitado", "Guest");
		en.put("Local comercial", "Business");
		en.put("Locales comerciales", "Business");
		en.put("Mayor que", "Greater than");
		en.put("Menor que", "Less than");
		en.put("Nombre", "Name");
		en.put("perfil", "profile");
		en.put("Precio", "Price");
		en.put("Piso", "Flat");
		en.put("Pisos", "Flats");
		en.put("Por favor, intentelo de nuevo mas tarde", "Please, try again later");
		en.put("principal", "home");
		en.put("Principal", "Home");
		en.put("propiedades", "properties");
		en.put("publicar", "publish");
		en.put("Publicar", "Publish");
		en.put("salir", "logout");
		en.put("Sin resultados", "There is not any result.");
		en.put("Sig", "Next");
		en.put("Solar", "Plot");
		en.put("Solares", "Plots");
		en.put("Tipo de oferta", "Offer type");
		en.put("Tipo de propiedad", "Property type");
		en.put("Registrarse", "Register");
		en.put("Usuario", "User");
		en.put("usuarios", "users");
		en.put("Venta", "Sell");
		langMap.put("en", en);
	}
	
	public void setLanguage(int l) {
		switch (l) {
			case ES: lang="es"; break;
			case EN: lang="en";
		}
	}
	
	public void setLanguage(String l) {
		if (l.equals("es") || l.equals("en"))
			lang = l;
	}
	
	public String getLanguage() {
		return lang;
	}
	
	public String translate(String word) {
		try{
			return (lang.equals("es")) ? word : langMap.get(lang).get(word);
		} catch (Exception e) {
			return "Translation FAIL";
		}
	}
}
